package org.NooLab.itexx.app.controller.results;

import java.io.Serializable;
import java.util.ArrayList;

import org.NooLab.itexx.ITexxWindowCommons;
import org.NooLab.itexx.retrieval.ResultsDigester;
import org.NooLab.utilities.logging.PrintLog;
import org.NooLab.utilities.strings.StringsUtil;



/**
 *  each item will contain the google html for the respective item,
	including raw html, links and "text only", the main target URL,
	and the full html of the main target URL
	
	-> that is, this class will retrieve the web pages for the URL!
 * 
 *
 */
public class SearchEngineResults implements Serializable{

	
	ArrayList<SearchEngineResultItem> items = new ArrayList<SearchEngineResultItem>();
	
	transient ResultsDigester resultsDigester;
	transient ITexxWindowCommons appCommons;
	
	transient StringsUtil strgutil = new StringsUtil();
	transient PrintLog out;
	
	// ========================================================================
	// used by the ResultsDigester for the list relative to the request
	public SearchEngineResults(ITexxWindowCommons commons, ResultsDigester resultsDigester){
		
		// resultsDigester is created upon factual results only, there is no "host" for it
		this.resultsDigester = resultsDigester;
		appCommons = commons;
		
		out = appCommons.out ;
	}

	// used by the session manager for the global list
	public SearchEngineResults(ITexxWindowCommons commons) {
		appCommons = commons;
		
		appCommons.setSearchEngineResults(this);
		out = appCommons.out ;
	}

	// ========================================================================	
	

	public void clear() {
		// 
		items.clear();
	}

	public int size(){
		return items.size();
	}
	
	public void add(SearchEngineResultItem item){
		items.add(item) ;
	}

	public SearchEngineResultItem get(int index) {
		SearchEngineResultItem item = null;
		
		if ((index>=0) && (index<items.size())){
			item = items.get(index);
		}
		return item;
	}

	
	public ArrayList<SearchEngineResultItem> getItems() {
		return items;
	}

	public void setItems(ArrayList<SearchEngineResultItem> items) {
		this.items = items;
	}
	
	
	
}
